package com.sxjh.enums;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.Arrays;
import java.util.Optional;

/**
 * <p>
 * 内部倒运流程节点
 * </p>
 *
 * @author guanxy
 * @since 2023-05-29
 */
@Getter
@RequiredArgsConstructor
public enum NodeEnum {

    ONE(1, "初磅"),
    TWO(2, "装车拍照"),
    THREE(3, "复磅"),
    FOUR(4, "卸车拍照"),
    FIVE(5, "刷卡确认");

    private final int order;

    private final String description;

    public static NodeEnum getNextNode(int order) {
        order = order + 1;
        int finalOrder = order;
        NodeEnum[] values = NodeEnum.values();
        Optional<NodeEnum> first = Arrays.stream(values).filter(e -> e.getOrder() == finalOrder).findFirst();
        return first.orElse(NodeEnum.ONE);
    }

    public static String getCurrNodeName(int order) {
        if (order == 0) {
            return "未执行";
        }
        int finalOrder = order;
        NodeEnum[] values = NodeEnum.values();
        NodeEnum first = Arrays.stream(values).filter(e -> e.getOrder() == finalOrder).findFirst().orElse(null);
        if (first == null) {
            return "未执行";
        }
        return first.description;
    }
}
